package com.xiyu.service.repository.mailbox.mail;

import com.xiyu.service.model.mailbox.mail.MailboxMailResource;
import com.xiyu.service.model.mailbox.mail.MailboxMailResourceTable;
import org.babyfish.jimmer.spring.repository.JRepository;

import java.util.Optional;
import java.util.List;

public interface MailboxMailResourceRepository extends JRepository<MailboxMailResource, Long> {
    MailboxMailResourceTable mailboxMailResourceTable = MailboxMailResourceTable.$;

    default List<MailboxMailResource> findByMailIdAndResourceType(Long mailId, Integer resourceType){
        return sql().createQuery(mailboxMailResourceTable)
                .where(mailboxMailResourceTable.mailId().eq(mailId))
                .where(mailboxMailResourceTable.resourceType().eq(resourceType))
                .orderBy(mailboxMailResourceTable.id())
                .select(mailboxMailResourceTable).execute();
    };

    Optional<MailboxMailResource> findFirstByMailIdAndFileName(Long mailId, String fileName);

}